#include <iostream>
#include <cstdio>
using namespace std;
int root(int x){
	if(x<10) return x;
	int _x=0;
	while(x!=0){
		_x=_x+x%10;
		x/=10;
	}
	if(_x<10)return _x;
	else return root(_x);
}
int main(){
	int n;
	cin>>n;
	cout<<root(n);
	return 0;
}
